#include "DataTypeCompany.h"

#include <sstream>
#include <stdio.h>

#define GLOG_USE_GLOG_EXPORT
#include <glog/logging.h>

DataTypeCompany::DataTypeCompany()
{
}

DataTypeCompany::~DataTypeCompany()
{
}

int DataTypeCompany::callback(void *data, int argc, char *argv[], char *columns[])
{
    DataTypeCompany *pthis = (DataTypeCompany *)data;
    int              i;
    for (i = 0; i < argc; i++) {
        printf("%s = %s\n", columns[i], argv[i] ? argv[i] : "NULL");
    }
    printf("%s\n", pthis->getName().c_str());
    return 0;
}

std::string DataTypeCompany::getCreateSql()
{
    return std::string("CREATE TABLE COMPANY("
                       "ID INT PRIMARY KEY     NOT NULL,"
                       "NAME           TEXT    NOT NULL,"
                       "AGE            INT     NOT NULL,"
                       "ADDRESS        CHAR(50),"
                       "SALARY         REAL );");
}

std::string DataTypeCompany::getInsertSql(const company_t &company)
{
    std::ostringstream oss;
    oss << "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (" << company.id << ",'" << company.name << "'," << company.age << ",'"
        << company.address << "'," << company.salary << ");";
    return oss.str();
}

std::string DataTypeCompany::getSelectSql()
{
    return std::string("SELECT * from COMPANY");
}

std::string DataTypeCompany::getName()
{
    return "Hello, i'm DataTypeCompany";
}